import { director, find, instantiate, Node, Prefab, SpriteFrame } from "cc";
import { AssetLoader } from "../scripts/framework/loader/AssetLoader";
import { LoaderMgr } from "../scripts/framework/loader/LoaderMgr";

export class WindowNodeLastLoader {

    public node: Node;

    public loader: AssetLoader;

    public name: string;

    constructor(name: string) {
        this.name = name;
        this.loader = LoaderMgr.getInstance().get(this);
        this.onCtor();
    }

    onCtor(): void {
        this.loader.load(this.name, Prefab, (err: Error, prefab: Prefab) => {
            this.node = instantiate(prefab);
            this.node.setParent(window.windowParentNode);
            this.loader.load('images/common/btn_close', SpriteFrame, (err, asset: SpriteFrame) => {
                if (err) {
                    console.log(err);
                    return;
                }
                console.log('进入了加载回调');
            }, 'test_asset');

            this.loader.loadDir("view",SpriteFrame,(err,assets)=>{
                if (err) {
                    console.log(err);
                    return;
                }
                console.log('进入了加载回调 loadDir');
            });

            
            this.loader.loadArray([
                "setting/setting1",
                "setting/setting2",
                "setting/setting3",
                "setting/setting4"],
                SpriteFrame,(err,assets)=>{
                if (err) {
                    console.log(err);
                    return;
                }
                console.log('进入了加载回调 loadArray');
            });
            LoaderMgr.getInstance().releaseLoader(this);
            this.node.destroy();
        }, 'test1')
    }

    // close(): void {
    //     LoaderMgr.getInstance().releaseLoader(this.name);
    //     this.node.destroy();
    // }

}
